//
//  UIBarButtonItem+Extension.swift
//  Home_School_08
//
//  Created by 张晓林 on 2016/12/23.
//  Copyright © 2016年 张晓林. All rights reserved.
//

import UIKit

extension UIBarButtonItem {

    convenience init?(imageName: String, target: Any?, action: Selector) {
        // 初始化一个按钮
        let btn = UIButton(type: .custom)
        // 获得图片
       guard let imgNomal = UIImage(named: "\(imageName)_nor"),
        let imgH = UIImage(named: "\(imageName)_press") else {
            return nil
        }
        
        btn.frame = CGRect(x: 0, y: 0, width: imgNomal.size.width, height: imgNomal.size.height)
        
        btn.setBackgroundImage(imgNomal, for: .normal)
        btn.setBackgroundImage(imgH, for: .highlighted)
        
        // 添加监听事件
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        self.init(customView: btn)
    }

}
